import show_modal from './index.js'

// const xt_show_modal = {
//     install: (app, options) =>{

//         uni.$showModal = show_modal_fun
//     }
// };
const show_modal_fun = function(op = {}) {
	//#ifdef APP-PLUS
	return new Promise((resolve, reject) => {
		let moc = new show_modal({
			...op,
			$event: function(e) {
				if (e.res) {
					resolve(e);
				} else {
					reject(e);
				}
			}
		})
		moc.show();
	})
	//#endif

	//#ifdef H5 || MP
	var promise = uni.showModal({
		title: op.title,
		content: op.content,
		showCancel: !op.delCancel,
		cancelText: op.cancelVal,
		confirmText: op.confirmVal,
	});

	return new Promise((resolve, reject) => {
		promise.then(data => {
			var [err, res] = data;
			if (res.confirm) {
				resolve()
			} else {
				reject();
			}
		})
	})

	//#endif

}

export default show_modal_fun;